$(function() {
	

	/***********  song start ****************/
	var jQ_provinceList = $('#js_provinceList'),
	jQ_cityList = $('#js_cityList');
	jQ_provinceList.change(function(){
		var _url = jQ_provinceList.data('url');
		var _data = {id: jQ_provinceList.val()};
		$.get(_url, _data, function(data){
			var res = eval('('+data+')');
			if(res.status == 'success'){
				var _subData = res.result;
				jQ_cityList.html('');
				if(_subData.length>0){
					$("<option value='0'>请选择问题</option>").appendTo("#js_cityList");
					for (var i in _subData){
						$("<option value="+_subData[i].id+">"+_subData[i].name+"</option>").appendTo("#js_cityList");
					}
				} else {
					$("<option value='' selected='selected'>请选择问题</option>").appendTo("#js_cityList");
				}
			}
		});
	});
	jQ_provinceList.change(function(){
		var index = document.getElementById("js_provinceList").selectedIndex;
		var indextwo = document.getElementById("js_cityList").selectedIndex;
		$("#categoryone").text(this.options[index].text);
		$("#categorytwo").text('请选择问题');
	})
	jQ_cityList.change(function(){
		var index = document.getElementById("js_cityList").selectedIndex;
		$("#categorytwo").text(this.options[index].text);
	})

	//upload
	var jQ_uploader = $("#js_uploader"),
	jQ_imgurl = $("#js_imgurl");

	jQ_uploader.fileuploader({
		request: jQ_uploader.data("url"),
		complete: function(id, data) {
			var uploadedImg = jQ_uploader.siblings('.fileuploader-container').find('.qq-upload-file').text();
			
			if($.isArray(data.result)) {
				jQ_uploader.val(data.result[1]);
				jQ_imgurl.val(data.result[0]);
			}
		}
	});

	var jQ_buttonSubmitQ = $("#js_buttonSubmitQ"),
	jQ_questionContent = $("#js_questionContent");
	jQ_buttonSubmitQ.click(function(e){
		// e.preventDefault();
		var _url = jQ_buttonSubmitQ.data('url'); 
		var _data = {
			pid: jQ_cityList.val(),
			imgurl: jQ_imgurl.val(),
			content: $.trim(jQ_questionContent.val()),
		};
		if(jQ_cityList.val() == 0){
			lay('请选择问题类型！');
		} else if(!$.trim(jQ_questionContent.val())){
			lay('请填写问题描述！');
		}else {
			$.get(_url, _data, function(data){
				var res = eval('('+data+')');
				if (res.status == 'success'){
				location.assign("/user/myquestions?i=myask");
				}else {
					lay('问题提交失败！');
				}			
			});
		};
	});

	/***********  song end ****************/

	/*********** lay out start ***************/
	/*function lay(msg){
		var html = '<div class="lay-wrap"></div>'+
		'<div class="lay-box" style="display:block;">'+
		'<div class="lay-header">提示信息</div>'+
		'<div class="lay-body">' + msg + '</div>'+
		'<div class="lay-footer">确认</div>'+
		'</div>'
		$('body').append(html);
		$(document).on('click','.lay-footer',function(){
			$(this).parent().hide();
			$('.lay-wrap').remove();
			$('.lay-box').remove();
		})
	}*/

	/*************** lay out end ***************/


});